home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-07-14 | 54.5 KB | 1,974 lines | [TEXT/CWIE] |
- /*************************************************************************************
-
- File: ISpPlugInUI.cp
-
- Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
-
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- *************************************************************************************/
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __SOUND__
- #include <Sound.h>
- #endif
-
- #include "Common.h"
- #include "ISpPlugInUI.h"
- #include <InputSprocket.h>
- #include "InputSprocketDriver.h"
- #include "dprintf.h"
- #include "DialogUtils.h"
-
- #if FORCE_FB
- #include "I•Force.h"
- #include "InputSprocketForceFeedback.h"
- #endif
-
- // most of this file is not speed dependet
- // we reset near the bottom for the functions
- // that might be used during data gathering
- #if __MWERKS__
- #pragma optimize_for_size on
- #endif
-
- // valid need kinds for device types
- static const UInt16 validMouseKindsCount = 5;
- static ISpElementKind validMouseKinds[validMouseKindsCount] =
- { kISpElementKind_Delta,
- kISpElementKind_Movement,
- kISpElementKind_Axis,
- kISpElementKind_DPad,
- kISpElementKind_Button};
-
- static const UInt16 validDeltaKindsCount = 3;
- static ISpElementKind validDeltaKinds[validDeltaKindsCount] =
- { kISpElementKind_Delta,
- kISpElementKind_Axis,
- kISpElementKind_Button};
-
- static const UInt16 validStickKindsCount = 4;
- static ISpElementKind validStickKinds[validStickKindsCount] =
- { kISpElementKind_Movement,
- kISpElementKind_Axis,
- kISpElementKind_DPad,
- kISpElementKind_Button};
-
- static const UInt16 validAxisKindsCount = 2;
- static ISpElementKind validAxisKinds[validAxisKindsCount] =
- { kISpElementKind_Axis,
- kISpElementKind_Button };
-
- static const UInt16 validPOVKindsCount = 4;
- static ISpElementKind validPOVKinds[validPOVKindsCount] =
- { kISpElementKind_DPad,
- kISpElementKind_Movement,
- kISpElementKind_Axis,
- kISpElementKind_Button };
-
- static const UInt16 validButtonKindsCount = 1;
- static ISpElementKind validButtonKinds[validButtonKindsCount] =
- { kISpElementKind_Button };
-
-
-
- // methods
-
- ISpPlugInUI::ISpPlugInUI (void)
- {
- thumbprint = kThumbprint;
- }
-
- OSStatus ISpPlugInUI::MHInit( UInt32 refCon,
- UInt32 count,
- ISpNeed needs[],
- ISpElementReference virtualElements[],
- Boolean used[],
- OSType appCreatorCode,
- OSType subCreatorCode,
- UInt32 reserved1,
- void* reserved2)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->Init(count,
- needs,
- virtualElements,
- used,
- appCreatorCode,
- subCreatorCode,
- reserved1,
- reserved2);
- }
-
- OSStatus ISpPlugInUI::MHStop(UInt32 refCon)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->Stop();
- }
-
- OSStatus ISpPlugInUI::MHGetSize(UInt32 refCon, Point *minimum, Point *best)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->GetSize(*minimum, *best);
- }
-
- OSStatus ISpPlugInUI::MHHandleEvent(UInt32 refCon, EventRecord *theEvent, Boolean *handled)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->HandleEvent(*theEvent, *handled);
- }
-
- OSStatus ISpPlugInUI::MHShow(UInt32 refCon, DialogPtr theDialog, short dialogItemNumber, Rect *r)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->Show(theDialog, dialogItemNumber, *r);
- }
-
- OSStatus ISpPlugInUI::MHHide(UInt32 refCon)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->Hide();
- }
-
- OSStatus ISpPlugInUI::MHBeginConfiguration(UInt32 refCon, UInt32 count, ISpNeed needs[])
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->BeginConfiguration(count, needs);
- }
-
- OSStatus ISpPlugInUI::MHEndConfiguration(UInt32 refCon, Boolean accept)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->EndConfiguration(accept);
- }
-
- OSStatus ISpPlugInUI::MHGetIcon(UInt32 refCon, short *iconSuiteResourceId)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->GetIcon(*iconSuiteResourceId);
- }
-
- OSStatus ISpPlugInUI::MHGetState(UInt32 refCon, UInt32 buflen, void *buffer, UInt32 *length)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->GetState(buflen, buffer, *length);
- }
-
- OSStatus ISpPlugInUI::MHSetState(UInt32 refCon, UInt32 length, void *buffer)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->SetState(length, buffer);
- }
-
- OSStatus ISpPlugInUI::MHDirty(UInt32 refCon, Boolean *dirty)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->Dirty(*dirty);
- }
-
- OSStatus ISpPlugInUI::MHSetActive(UInt32 refCon, Boolean active)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->SetActive(active);
- }
-
- OSStatus ISpPlugInUI::MHDialogItemHit(UInt32 refCon, short itemHit)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->DialogItemHit(itemHit);
- }
-
- OSStatus ISpPlugInUI::MHTickle(UInt32 refCon)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->Tickle();
- }
-
- OSStatus ISpPlugInUI::MHInterruptTickle(UInt32 refCon)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->InterruptTickle();
- }
-
- OSStatus ISpPlugInUI::MHDraw(UInt32 refCon)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->Draw();
- }
-
-
- OSStatus ISpPlugInUI::MHClick(UInt32 refCon, const EventRecord *event)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->Click(*event);
- }
-
- OSStatus ISpPlugInUI::MHADBReInit(UInt32 refCon, Boolean inPostProcess)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- return plugIn->ADBReInit(inPostProcess);
- }
-
- #if FORCE_FB
-
- OSStatus ISpPlugInUI::MHBuffeting(UInt32 refCon, UInt32 inMagnitude)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if (!IF_Buffeting (inMagnitude))
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHBuffetingClear(UInt32 refCon)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_BuffetingClear ())
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHButtonReflexJolt(UInt32 refCon, UInt32 inButton, UInt32 inMagnitude, SInt32 inDirection, UInt32 inDuration, UInt32 inRepeatRate)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_ButtonReflexJolt (inButton, inMagnitude, inDirection, inDuration, inRepeatRate))
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHButtonReflexClear(UInt32 refCon, UInt32 inButton)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_ButtonReflexClear (inButton))
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHJolt(UInt32 refCon, UInt32 inMagnitude, SInt32 inDirection, UInt32 inDuration)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_Jolt (inMagnitude, inDirection, inDuration))
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHXVibration(UInt32 refCon, UInt32 inLeftMagnitude, UInt32 inRightMagnitude, UInt32 inFrequency)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_XVibration (inLeftMagnitude, inRightMagnitude, inFrequency))
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHXVibrationClear(UInt32 refCon)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_XVibrationClear ())
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHYVibration(UInt32 refCon, UInt32 inUpMagnitude, UInt32 inDownMagnitude, UInt32 inFrequency)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_YVibration (inUpMagnitude, inDownMagnitude, inFrequency))
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHYVibrationClear(UInt32 refCon)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_YVibrationClear ())
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHVectorForce(UInt32 refCon, UInt32 inMagnitude, SInt32 inDirection)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_VectorForce (inMagnitude, inDirection))
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHVectorForceClear(UInt32 refCon)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_VectorForceClear ())
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHXYVectorForce(UInt32 refCon, SInt32 inXMagnitude, SInt32 inYMagnitude)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_XYVectorForce (inXMagnitude, inYMagnitude))
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHXSpring(UInt32 refCon, SInt32 inOrigin, UInt32 inLeftStiffness, UInt32 inRightStiffness)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_XSpring (inOrigin, inLeftStiffness, inRightStiffness))
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHXSpringClear(UInt32 refCon)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_XSpringClear ())
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHYSpring(UInt32 refCon, SInt32 inOrigin, UInt32 inUpStiffness, UInt32 inDownStiffness)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_YSpring (inOrigin, inUpStiffness, inDownStiffness))
- status = -1;
-
- return status;
- }
-
- OSStatus ISpPlugInUI::MHYSpringClear(UInt32 refCon)
- {
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, paramErr);
-
- OSStatus status = noErr;
- if(!IF_YSpringClear ())
- status = -1;
-
- return status;
- }
-
- #endif /* FORCE_FB */
-
- ISpDriverFunctionPtr_Generic ISpPlugInUI::MetaHandler(UInt32 refCon, ISpMetaHandlerSelector selector)
- {
- ISpDriverFunctionPtr_Generic function = NULL;
-
- ISpPlugInUI *plugIn = (ISpPlugInUI *) refCon;
- CHECK(plugIn->thumbprint == kThumbprint, NULL);
-
- switch(selector)
- {
- case kISpSelector_Init:
- ISpDriverFunctionPtr_Init funcInit = (ISpDriverFunctionPtr_Init) ISpPlugInUI::MHInit;
- function = (ISpDriverFunctionPtr_Generic) funcInit;
- break;
-
- case kISpSelector_Stop:
- ISpDriverFunctionPtr_Stop funcStop = (ISpDriverFunctionPtr_Stop) ISpPlugInUI::MHStop;
- function = (ISpDriverFunctionPtr_Generic) funcStop;
- break;
-
- case kISpSelector_GetSize:
- ISpDriverFunctionPtr_GetSize funcGetSize = (ISpDriverFunctionPtr_GetSize) ISpPlugInUI::MHGetSize;
- function = (ISpDriverFunctionPtr_Generic) funcGetSize;
- break;
-
- case kISpSelector_HandleEvent:
- ISpDriverFunctionPtr_HandleEvent funcHandleEvent = (ISpDriverFunctionPtr_HandleEvent) ISpPlugInUI::MHHandleEvent;
- function = (ISpDriverFunctionPtr_Generic) funcHandleEvent;
- break;
-
- case kISpSelector_Show:
- ISpDriverFunctionPtr_Show funcShow = (ISpDriverFunctionPtr_Show) ISpPlugInUI::MHShow;
- function = (ISpDriverFunctionPtr_Generic) funcShow;
- break;
-
- case kISpSelector_Hide:
- ISpDriverFunctionPtr_Hide funcHide = (ISpDriverFunctionPtr_Hide) ISpPlugInUI::MHHide;
- function = (ISpDriverFunctionPtr_Generic) funcHide;
- break;
-
- case kISpSelector_BeginConfiguration:
- ISpDriverFunctionPtr_BeginConfiguration funcBeginConfiguration = (ISpDriverFunctionPtr_BeginConfiguration) ISpPlugInUI::MHBeginConfiguration;
- function = (ISpDriverFunctionPtr_Generic) funcBeginConfiguration;
- break;
-
- case kISpSelector_EndConfiguration:
- ISpDriverFunctionPtr_EndConfiguration funcEndConfiguration = (ISpDriverFunctionPtr_EndConfiguration) ISpPlugInUI::MHEndConfiguration;
- function = (ISpDriverFunctionPtr_Generic) funcEndConfiguration;
- break;
-
- case kISpSelector_GetIcon:
- ISpDriverFunctionPtr_GetIcon funcGetIcon = (ISpDriverFunctionPtr_GetIcon) ISpPlugInUI::MHGetIcon;
- function = (ISpDriverFunctionPtr_Generic) funcGetIcon;
- break;
-
- case kISpSelector_GetState:
- ISpDriverFunctionPtr_GetState funcGetState = (ISpDriverFunctionPtr_GetState) ISpPlugInUI::MHGetState;
- function = (ISpDriverFunctionPtr_Generic) funcGetState;
- break;
-
- case kISpSelector_SetState:
- ISpDriverFunctionPtr_SetState funcSetState = (ISpDriverFunctionPtr_SetState) ISpPlugInUI::MHSetState;
- function = (ISpDriverFunctionPtr_Generic) funcSetState;
- break;
-
- case kISpSelector_Dirty:
- ISpDriverFunctionPtr_Dirty funcDirty = (ISpDriverFunctionPtr_Dirty) ISpPlugInUI::MHDirty;
- function = (ISpDriverFunctionPtr_Generic) funcDirty;
- break;
-
- case kISpSelector_SetActive:
- ISpDriverFunctionPtr_SetActive funcSetActive = (ISpDriverFunctionPtr_SetActive) ISpPlugInUI::MHSetActive;
- function = (ISpDriverFunctionPtr_Generic) funcSetActive;
- break;
-
- case kISpSelector_DialogItemHit:
- ISpDriverFunctionPtr_DialogItemHit funcDialogItemHit = (ISpDriverFunctionPtr_DialogItemHit) ISpPlugInUI::MHDialogItemHit;
- function = (ISpDriverFunctionPtr_Generic) funcDialogItemHit;
- break;
-
- case kISpSelector_Tickle:
- ISpDriverFunctionPtr_Tickle funcTickle = (ISpDriverFunctionPtr_Tickle) ISpPlugInUI::MHTickle;
- function = (ISpDriverFunctionPtr_Generic) funcTickle;
- break;
-
- case kISpSelector_InterruptTickle:
- ISpDriverFunctionPtr_InterruptTickle funcInterruptTickle = (ISpDriverFunctionPtr_InterruptTickle) ISpPlugInUI::MHInterruptTickle;
- function = (ISpDriverFunctionPtr_Generic) funcInterruptTickle;
- break;
-
- case kISpSelector_Draw:
- ISpDriverFunctionPtr_Draw funcDraw = (ISpDriverFunctionPtr_Draw) ISpPlugInUI::MHDraw;
- function = (ISpDriverFunctionPtr_Generic) funcDraw;
- break;
-
- case kISpSelector_Click:
- ISpDriverFunctionPtr_Click funcClick = (ISpDriverFunctionPtr_Click) ISpPlugInUI::MHClick;
- function = (ISpDriverFunctionPtr_Generic) funcClick;
- break;
-
- case kISpSelector_ADBReInit:
- ISpDriverFunctionPtr_ADBReInit funcADBReInit = (ISpDriverFunctionPtr_ADBReInit) ISpPlugInUI::MHADBReInit;
- function = (ISpDriverFunctionPtr_Generic) funcADBReInit;
- break;
-
- #if FORCE_FB
- case kISpSelector_Buffeting:
- ISpDriverFunctionPtr_Buffeting funcBuffeting = ISpPlugInUI::MHBuffeting;
- function = (ISpDriverFunctionPtr_Generic) funcBuffeting;
- break;
-
- case kISpSelector_BuffetingClear:
- ISpDriverFunctionPtr_BuffetingClear funcBuffetingClear = ISpPlugInUI::MHBuffetingClear;
- function = (ISpDriverFunctionPtr_Generic) funcBuffetingClear;
- break;
-
- case kISpSelector_ButtonReflexJolt:
- ISpDriverFunctionPtr_ButtonReflexJolt funcButtonReflexJolt = ISpPlugInUI::MHButtonReflexJolt;
- function = (ISpDriverFunctionPtr_Generic) funcButtonReflexJolt;
- break;
-
- case kISpSelector_ButtonReflexClear:
- ISpDriverFunctionPtr_ButtonReflexClear funcButtonReflexClear = ISpPlugInUI::MHButtonReflexClear;
- function = (ISpDriverFunctionPtr_Generic) funcButtonReflexClear;
- break;
-
- case kISpSelector_Jolt:
- ISpDriverFunctionPtr_Jolt funcJolt = ISpPlugInUI::MHJolt;
- function = (ISpDriverFunctionPtr_Generic) funcJolt;
- break;
-
- case kISpSelector_XVibration:
- ISpDriverFunctionPtr_XVibration funcXVibration = ISpPlugInUI::MHXVibration;
- function = (ISpDriverFunctionPtr_Generic) funcXVibration;
- break;
-
- case kISpSelector_XVibrationClear:
- ISpDriverFunctionPtr_XVibrationClear funcXVibrationClear = ISpPlugInUI::MHXVibrationClear;
- function = (ISpDriverFunctionPtr_Generic) funcXVibrationClear;
- break;
-
- case kISpSelector_YVibration:
- ISpDriverFunctionPtr_YVibration funcYVibration = ISpPlugInUI::MHYVibration;
- function = (ISpDriverFunctionPtr_Generic) funcYVibration;
- break;
-
- case kISpSelector_YVibrationClear:
- ISpDriverFunctionPtr_YVibrationClear funcYVibrationClear = ISpPlugInUI::MHYVibrationClear;
- function = (ISpDriverFunctionPtr_Generic) funcYVibrationClear;
- break;
-
- case kISpSelector_VectorForce:
- ISpDriverFunctionPtr_VectorForce funcVectorForce = ISpPlugInUI::MHVectorForce;
- function = (ISpDriverFunctionPtr_Generic) funcVectorForce;
- break;
-
- case kISpSelector_VectorForceClear:
- ISpDriverFunctionPtr_VectorForceClear funcVectorForceClear = ISpPlugInUI::MHVectorForceClear;
- function = (ISpDriverFunctionPtr_Generic) funcVectorForceClear;
- break;
-
- case kISpSelector_XYVectorForce:
- ISpDriverFunctionPtr_XYVectorForce funkXYVectorForce = ISpPlugInUI::MHXYVectorForce;
- function = (ISpDriverFunctionPtr_Generic) funkXYVectorForce;
- break;
-
- case kISpSelector_XSpring:
- ISpDriverFunctionPtr_XSpring funkXSpring = ISpPlugInUI::MHXSpring;
- function = (ISpDriverFunctionPtr_Generic) funkXSpring;
- break;
-
- case kISpSelector_XSpringClear:
- ISpDriverFunctionPtr_XSpringClear funkXSpringClear = ISpPlugInUI::MHXSpringClear;
- function = (ISpDriverFunctionPtr_Generic) funkXSpringClear;
- break;
-
- case kISpSelector_YSpring:
- ISpDriverFunctionPtr_YSpring funkYSpring = ISpPlugInUI::MHYSpring;
- function = (ISpDriverFunctionPtr_Generic) funkYSpring;
- break;
-
- case kISpSelector_YSpringClear:
- ISpDriverFunctionPtr_YSpringClear funkYSpringClear = ISpPlugInUI::MHYSpringClear;
- function = (ISpDriverFunctionPtr_Generic) funkYSpringClear;
- break;
-
- #endif /* FORCE_FB */
-
- }
-
- return function;
- }
-
- OSStatus ISpPlugInUI::Dirty(Boolean &dirty)
- {
- dirty = mDirty;
- mDirty = false;
-
- return noErr;
- }
-
- /* =============================================================================
- * SetDialogControl (private)
- *
- * CHanges the value of the control whose dialog item number is inItem in the
- * original DITL.
- * ========================================================================== */
- void ISpPlugInUI::SetDialogControl(
- short inRelDialogItem,
- short inValue)
- {
- short itemType;
- Handle itemHandle;
- Rect itemBounds;
- short item = inRelDialogItem+mBaseDITLCount;
-
- WARNING(mDialog != nil, "ISpPlugInUI::SetDialogControl mDialog == nil");
- WARNING(item <= CountDITL(mDialog), "ISpPlugInUI::SetDialogControl inRelDialogItem to large");
- WARNING(inRelDialogItem > 0, "ISpPlugInUI::SetDialogControl inRelDialogItem <= 0");
-
- GetDialogItem(mDialog, item, &itemType, &itemHandle, &itemBounds);
- WARNING(itemHandle != nil, "ISpPlugInUI::SetDialogControl Handle == nil");
- WARNING(itemType & ctrlItem, "ISpPlugInUI::SetDialogControl: (itemType & ctrlItem) == 0");
-
- if ((itemType & ctrlItem) && itemHandle != nil)
- SetControlValue((ControlHandle) itemHandle, inValue);
- }
-
- ISpPlugInUI::DirectionType ISpPlugInUI::GetDirection2D(ISpElementLabel label)
- {
- DirectionType direction;
- DirectionType direction2D;
-
- direction = GetDirection(label);
-
- switch(direction)
- {
- case kDirection_X:
- case kDirection_Roll:
- case kDirection_Yaw:
- direction2D = kDirection_X;
- break;
-
- case kDirection_Y:
- case kDirection_Z:
- case kDirection_Pitch:
- direction2D = kDirection_Y;
- break;
-
- case kDirection_None:
- default:
- direction2D = kDirection_None;
- }
-
- return direction2D;
- }
-
- ISpPlugInUI::DirectionType ISpPlugInUI::GetDirection(ISpElementLabel label)
- {
- DirectionType direction;
-
- switch(label)
- {
- case kISpElementLabel_Axis_XAxis:
- case kISpElementLabel_Delta_X:
- case kISpElementLabel_Btn_SlideLeft:
- case kISpElementLabel_Btn_SlideRight:
- direction = kDirection_X;
- break;
-
- case kISpElementLabel_Axis_YAxis:
- case kISpElementLabel_Delta_Y:
- direction = kDirection_Y;
- break;
-
- case kISpElementLabel_Axis_ZAxis:
- case kISpElementLabel_Axis_Gas:
- case kISpElementLabel_Delta_Z:
- case kISpElementLabel_Axis_Throttle:
- case kISpElementLabel_Btn_MoveForward:
- case kISpElementLabel_Btn_MoveBackward:
- direction = kDirection_Z;
- break;
-
- case kISpElementLabel_Axis_Rx:
- case kISpElementLabel_Axis_PitchTrim:
- case kISpElementLabel_Delta_Rx:
- case kISpElementLabel_Btn_LookUp:
- case kISpElementLabel_Btn_LookDown:
- direction = kDirection_Rx;
- break;
-
- case kISpElementLabel_Axis_Ry:
- case kISpElementLabel_Axis_YawTrim:
- case kISpElementLabel_Delta_Ry:
- direction = kDirection_Ry;
- break;
-
- case kISpElementLabel_Axis_Rz:
- case kISpElementLabel_Axis_RollTrim:
- case kISpElementLabel_Delta_Rz:
- case kISpElementLabel_Axis_Rudder:
- case kISpElementLabel_Btn_TurnLeft:
- case kISpElementLabel_Btn_TurnRight:
- case kISpElementLabel_Btn_LookLeft:
- case kISpElementLabel_Btn_LookRight:
- direction = kDirection_Rz;
- break;
-
- case kISpElementLabel_None:
- case kISpElementLabel_Axis_Brake:
- case kISpElementLabel_Axis_Clutch:
- case kISpElementLabel_Pad_POV:
- case kISpElementLabel_Pad_Move:
- case kISpElementLabel_Pad_POV_Horiz:
- case kISpElementLabel_Pad_Move_Horiz:
- case kISpElementLabel_Btn_Fire:
- case kISpElementLabel_Btn_SecondaryFire:
- case kISpElementLabel_Btn_Jump:
- case kISpElementLabel_Btn_PauseResume:
- case kISpElementLabel_Btn_Select:
- case kISpElementLabel_Btn_Next:
- case kISpElementLabel_Btn_Previous:
- case kISpElementLabel_Btn_SideStep:
- case kISpElementLabel_Btn_Run:
- case kISpElementLabel_Btn_Look:
- default:
- direction = kDirection_None;
- }
-
- return direction;
- }
-
- Boolean ISpPlugInUI::IsAppropriateNeedForButton(
- ISpNeed & need,
- ISpElementLabel buttonLabel)
- {
- buttonLabel;
-
- if ((need.theKind == kISpElementKind_Axis) && (need.flags & kISpNeedFlag_Axis_AlreadyButton))
- { return false; }
-
- if ((need.theKind == kISpElementKind_Delta) && (need.flags & kISpNeedFlag_Delta_AlreadyButton))
- { return false; }
-
- return true;
- }
-
- Boolean ISpPlugInUI::IsAppropriateNeedForDPad(
- ISpNeed & need,
- ISpElementLabel dpadLabel)
- {
- dpadLabel;
-
- if ((need.theKind == kISpElementKind_Axis) && (need.flags & kISpNeedFlag_Axis_AlreadyButton))
- { return false; }
-
- if ((need.theKind == kISpElementKind_Delta) && (need.flags & kISpNeedFlag_Delta_AlreadyButton))
- { return false; }
-
- return true;
- }
-
- Boolean ISpPlugInUI::IsAppropriateNeedForAxis(
- ISpNeed & need,
- ISpElementLabel axisLabel)
- {
- axisLabel;
-
- if ((need.theKind == kISpElementKind_Button) && (need.flags & kISpNeedFlag_Button_AlreadyAxis))
- { return false; }
-
- if ((need.theKind == kISpElementKind_Delta) && (need.flags & kISpNeedFlag_Delta_AlreadyAxis))
- { return false; }
-
- return true;
- }
-
- Boolean ISpPlugInUI::IsAppropriateNeedForDelta(
- ISpNeed & need,
- ISpElementLabel deltaLabel)
- {
- deltaLabel;
-
- if ((need.theKind == kISpElementKind_Button) && (need.flags & kISpNeedFlag_Button_AlreadyDelta))
- { return false; }
-
- if ((need.theKind == kISpElementKind_Button) && (need.flags & kISpNeedFlag_Button_AlreadyAxis))
- { return false; }
-
- if ((need.theKind == kISpElementKind_Axis) && (need.flags & kISpNeedFlag_Axis_AlreadyDelta))
- { return false; }
-
- return true;
- }
-
-
- /* =============================================================================
- * IsAppropriateNeed (private)
- *
- * Returns true if the indexed need is 'appropriate' for the specified element label.
- * ========================================================================== */
- Boolean ISpPlugInUI::IsAppropriateNeed(
- ISpNeed & need,
- ISpElementKind elementKind,
- ISpElementLabel elementLabel)
- {
- Boolean isAppropriate = true;
-
- // step 1 do direction service (return on failure)
- DirectionType needDirection = GetDirection2D(need.theLabel);
- DirectionType deviceDirection = GetDirection2D(elementLabel);
-
- if ((needDirection != kDirection_None) && (deviceDirection != kDirection_None))
- {
- if (needDirection != deviceDirection) { return false; }
- }
-
- // step 2 do datatype specific service
- switch(elementKind)
- {
- case kISpElementKind_Button: // physical device = button
- isAppropriate = IsAppropriateNeedForButton(need, elementLabel);
- break;
- case kISpElementKind_Axis: // physical device = axis
- isAppropriate = IsAppropriateNeedForAxis(need, elementLabel);
- break;
- case kISpElementKind_Delta: // physical device = delta
- isAppropriate = IsAppropriateNeedForDelta(need, elementLabel);
- break;
- case kISpElementKind_DPad: // physical device = dpad
- isAppropriate = IsAppropriateNeedForDPad(need, elementLabel);
- break;
- }
-
- return isAppropriate;
- }
-
- /* =============================================================================
- * CheckPopUpHit (protected)
- *
- * inputs:
- * inWhere - local coordinates of where the user clicked
- * inDialogItem - the dialog item you are checking to see if it was clicked
- * validKinds - an array of kinds that you want to be in the popup
- * numKinds - the size of the valid kinds array
- * inNeed - currently selected need
- *
- * ouputs:
- * clicked - true if a new item was selected, false otherwise
- * outNeed - if returning true then this is the newly selected need
- * ========================================================================== */
- Boolean ISpPlugInUI::CheckPopUpHit(
- Point inWhere,
- short inDialogItem,
- ISpElementKind elementKind,
- ISpElementLabel elementLabel,
- ISpElementKind *validKinds,
- UInt32 numKinds,
- UInt32 inNeed,
- UInt32 &outNeed)
- {
- #if DEBUG
- GrafPtr debug_graf_ptr; GetPort(&debug_graf_ptr);
- #endif
-
- WARNING(CountDITL(mDialog) >= inDialogItem, "ISpPlugInUI::CheckPopUpHit inDialogItem out of range");
- WARNING(debug_graf_ptr == mDialog, "ISpPlugInUI::CheckPopUpHit wrong port was set");
- WARNING((inNeed < mNumNeeds) || (inNeed == kUnsetIndex), "ISpPlugInUI::CheckPopUpHit inNeed out of range");
- WARNING(numKinds != 0, "ISpPlugInUI::CheckPopUpHit numKinds was zero");
- WARNING(validKinds != nil, "ISpPlugInUI::CheckPopUpHit validKinds was nil");
- // NOTE: add assert to make sure the temp menu does not already exist
-
- OSStatus status = noErr;
-
- // whether an item was selected in popup
- Boolean result = false;
-
-
- // invisable ?
- if (DialogItemIsInvisable (mDialog, inDialogItem)) // if item is hidden, return false
- { return false; }
-
- // did we miss the popup ?
- Rect itemBounds;
- DialogItem_GetRect(mDialog, inDialogItem, &itemBounds);
-
- if (!PtInRect(inWhere, &itemBounds))
- { return false; }
-
- // do the actual work
- short inMenuItem = 0;
-
- // preflight for memory
- WARNING(::FreeMem() >= 4096, "ISpPlugInUI::CheckPopUpHit low on memory");
- if (::FreeMem() < 4096) { SysBeep(12); return false; }
-
- // get the modifiers
- EventModifiers keyModifiers = GetKeyModifiers();
-
- // 1. build the menu
- MenuHandle theMenu = NewMenu(kMenuID_TempMenu, "\p");
- WARNING(theMenu != nil, "ISpPlugInUI: NewMenu built a nil menu");
-
- UInt32 menuItemCount = 0;
-
- UInt32 kindIndex = 0;
- UInt32 needIndex;
-
- UInt32 firstKindFound = kUnsetIndex;
- for (kindIndex = 0; kindIndex < numKinds; kindIndex++)
- {
- Boolean seperatorAdded = false;
-
- for(needIndex = 0; needIndex < mNumNeeds; needIndex++)
- {
- if (mNeeds[needIndex].theKind == validKinds[kindIndex] &&
- // only show appropriate labels unless option key is down (unless it was already selected)
- (needIndex == inNeed || (keyModifiers & optionKey) || IsAppropriateNeed (mNeeds[needIndex], elementKind, elementLabel)) &&
- // don't show needs with kISpNeedFlag_Utility bit set unless the option key is down (unless it was already selected)
- (needIndex == inNeed || (keyModifiers & optionKey) || !(mNeeds[needIndex].flags & kISpNeedFlag_Utility)))
- {
- if (!seperatorAdded)
- {
- if (firstKindFound == kUnsetIndex) { firstKindFound = kindIndex; }
- else if (firstKindFound != kindIndex)
- {
- AppendMenu(theMenu, "\p(-"); // for balance)
- menuItemCount++;
-
- seperatorAdded = true;
- }
- }
-
- menuItemCount++;
-
- AppendMenu(theMenu, "\pXXX"); // no meta characters
- SetMenuItemText(theMenu, menuItemCount, mNeeds[needIndex].name);
-
- WARNING(mNeeds[needIndex].name[0] != 0, "ISpPlugInUI::CheckPopUpHit appended a 0 length string");
-
- // 2. find the current item
- if (needIndex == inNeed)
- {
- inMenuItem = menuItemCount;
- }
- }
- }
- }
-
-
- // 2. add an item that contains nothing
- AppendMenu(theMenu, "\p(-"); // for balance)
- menuItemCount++;
-
- // 2.1 get the none string
- Str255 nothingString;
- GetIndString(nothingString, kStrList_PlugInUI, kStrList_PlugInUI_None);
- WARNING(nothingString[0] != 0, "CheckPopupHit failed to get none string");
-
- // 2.2 add it to the menu
- AppendMenu(theMenu, nothingString);
- menuItemCount++;
-
- // 2.5 check the seleceted item in the menu, or check the none item
- if (inMenuItem != 0)
- { CheckItem(theMenu, inMenuItem, true); }
- else
- { CheckItem(theMenu, menuItemCount, true); }
-
- // 3. find where to place the menu
- Point where;
- where.v = itemBounds.top;
- where.h = itemBounds.right;
-
- LocalToGlobal(&where);
-
- // 4. handle the menu click
- PlotPopupIcon(inDialogItem, ttSelected);
-
- InsertMenu(theMenu, -1);
-
- long thing = PopUpMenuSelect(theMenu, where.v, where.h, inMenuItem - 1);
-
- PlotPopupIcon(inDialogItem, ttNone);
-
- // 5. feed back the result
- short outMenuItem = thing & 0x0000FFFF;
-
-
- // 6. search for the item in our menu (same way we built it)
- result = false;
-
- menuItemCount = 0;
-
- firstKindFound = kUnsetIndex;
- for(kindIndex = 0; kindIndex < numKinds; kindIndex++)
- {
- Boolean seperatorAdded = false;
-
- for(needIndex = 0; needIndex < mNumNeeds; needIndex++)
- {
- if (mNeeds[needIndex].theKind == validKinds[kindIndex] &&
- // only show appropriate labels unless option key is down (unless it was already selected)
- (needIndex == inNeed || (keyModifiers & optionKey) || IsAppropriateNeed (mNeeds[needIndex], elementKind, elementLabel)) &&
- // don't show needs with kISpNeedFlag_Utility bit set unless the option key is down (unless it was already selected)
- (needIndex == inNeed || (keyModifiers & optionKey) || !(mNeeds[needIndex].flags & kISpNeedFlag_Utility)))
- {
- if (!seperatorAdded)
- {
- if (firstKindFound == kUnsetIndex)
- firstKindFound = kindIndex;
- else if (firstKindFound != kindIndex)
- {
- menuItemCount++;
- seperatorAdded = true;
- }
- }
-
- menuItemCount++;
-
- if (menuItemCount == outMenuItem)
- {
- outNeed = needIndex;
- result = true;
- break;
- }
- }
- }
- }
-
- if (outMenuItem == menuItemCount + 2)
- {
- outNeed = kUnsetIndex;
- result = true;
- }
-
- DeleteMenu(kMenuID_TempMenu);
- DisposeMenu(theMenu);
-
-
- return result;
- }
-
-
- /* =============================================================================
- * PlotPopupIcon (protected)
- *
- * Draws the icon that represents the current state of the popup menu dialog
- * user item, which is given by its actual position in the dialog items.
- * ========================================================================== */
- void ISpPlugInUI::PlotPopupIcon(
- short inItem, // absolute item number
- IconTransformType inTransform) // transform
- {
- UInt32 itemIndex = inItem - mBaseDITLCount; // index relative to our DITL
- UInt32 *dialogItemToNeedMapping = GetDialogItemToNeedMapping(); //
- UInt32 thisItem = dialogItemToNeedMapping[itemIndex];
- OSStatus status;
-
- NAG_RETURN(((thisItem <= mNumNeeds) || (thisItem == kUnsetIndex)), "ISpPlugInUI::PlotPopupIcon item out of range");
-
- // get icon suite from needs or set it to the none icon suite
- short iconSuiteID;
- if (thisItem != kUnsetIndex) { iconSuiteID = mNeeds[thisItem].iconSuiteResourceId; }
- else { iconSuiteID = kISpNoneIconSuite; }
-
- if (DialogItemIsInvisable (mDialog, inItem)) // if item is hidden, don't draw
- { return; }
-
- //handle hiliting the item if the element is active on the device
- if (IsPressed(inItem)) { inTransform |= kISpIconTransform_DeviceActive; }
-
- // set the port and draw the icon
- {
- GWorldState port_saver(mDialog); // set port to mDialog and restore on exit
-
- // Find the item's rectangle
- Rect itemBounds;
- DialogItem_GetRect(mDialog, inItem, &itemBounds);
-
- // Plot the Icon
- status = ISpPlotAppIconSuite(&itemBounds, atCenterRight, inTransform | ttLabel3, iconSuiteID);
- WARNING(status == noErr, "ISpPlotAppIconSuite failed in PlotPopupIcon");
- }
- }
-
- void ISpPlugInUI::HandleStickClick (
- Point where,
- short dialogItem,
- UInt32 upDialogItem,
- UInt32 downDialogItem,
- UInt32 leftDialogItem,
- UInt32 rightDialogItem,
- UInt32 oldNeed,
- UInt32 &newNeed)
- {
- UInt32 * dialogItemToNeedMapping = GetDialogItemToNeedMapping();
-
- UInt32 itemIndex = dialogItem - mBaseDITLCount;
-
- ISpElementLabel elementLabel;
-
- if (itemIndex == leftDialogItem || itemIndex == rightDialogItem)
- { elementLabel = kISpElementLabel_Axis_XAxis; }
- else
- { elementLabel = kISpElementLabel_Axis_YAxis; }
-
- if (CheckPopUpHit (where, dialogItem, kISpElementKind_Axis, elementLabel, validStickKinds, validStickKindsCount, oldNeed, newNeed) &&
- oldNeed != newNeed)
- {
- // clear old values (if necessary)
- if (oldNeed != kUnsetIndex) switch (mNeeds[oldNeed].theKind)
- {
- case kISpElementKind_Movement:
- case kISpElementKind_DPad:
- dialogItemToNeedMapping[upDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[downDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[leftDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[rightDialogItem] = kUnsetIndex;
- break;
-
- case kISpElementKind_Axis:
- if (itemIndex == upDialogItem || itemIndex == downDialogItem)
- {
- dialogItemToNeedMapping[upDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[downDialogItem] = kUnsetIndex;
- }
- else // (itemIndex == leftDialogItem || itemIndex == rightDialogItem)
- {
- dialogItemToNeedMapping[leftDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[rightDialogItem] = kUnsetIndex;
- }
- break;
- }
-
- // set new values
- if (newNeed == kUnsetIndex)
- {
- dialogItemToNeedMapping[itemIndex] = newNeed;
- }
- else switch (mNeeds[newNeed].theKind)
- {
- case kISpElementKind_Movement:
- case kISpElementKind_DPad:
- dialogItemToNeedMapping[upDialogItem] = newNeed;
- dialogItemToNeedMapping[downDialogItem] = newNeed;
- dialogItemToNeedMapping[leftDialogItem] = newNeed;
- dialogItemToNeedMapping[rightDialogItem] = newNeed;
- break;
-
- case kISpElementKind_Axis:
- if (itemIndex == upDialogItem || itemIndex == downDialogItem)
- {
- dialogItemToNeedMapping[upDialogItem] = newNeed;
- dialogItemToNeedMapping[downDialogItem] = newNeed;
- }
- else // (itemIndex == leftDialogItem || itemIndex == rightDialogItem)
- {
- dialogItemToNeedMapping[leftDialogItem] = newNeed;
- dialogItemToNeedMapping[rightDialogItem] = newNeed;
- }
- break;
-
- case kISpElementKind_Button:
- dialogItemToNeedMapping[itemIndex] = newNeed;
- break;
-
- }
-
- mDirty = true;
- SetVirtualElements ();
-
- PlotPopupIcon(upDialogItem + mBaseDITLCount, ttNone);
- PlotPopupIcon(downDialogItem + mBaseDITLCount, ttNone);
- PlotPopupIcon(leftDialogItem + mBaseDITLCount, ttNone);
- PlotPopupIcon(rightDialogItem + mBaseDITLCount, ttNone);
- }
- }
-
- void ISpPlugInUI::HandleMouseClick (
- Point where,
- short dialogItem,
- UInt32 upDialogItem,
- UInt32 downDialogItem,
- UInt32 leftDialogItem,
- UInt32 rightDialogItem,
- UInt32 oldNeed,
- UInt32 &newNeed)
- {
- UInt32 * dialogItemToNeedMapping = GetDialogItemToNeedMapping();
-
- UInt32 itemIndex = dialogItem - mBaseDITLCount;
-
- ISpElementLabel elementLabel;
-
- if (itemIndex == leftDialogItem || itemIndex == rightDialogItem)
- { elementLabel = kISpElementLabel_Delta_X; }
- else
- { elementLabel = kISpElementLabel_Delta_Y; }
-
- if (CheckPopUpHit (where, dialogItem, kISpElementKind_Delta, elementLabel, validMouseKinds, validMouseKindsCount, oldNeed, newNeed) &&
- oldNeed != newNeed)
- {
- // clear old values (if necessary)
- if (oldNeed != kUnsetIndex) switch (mNeeds[oldNeed].theKind)
- {
- case kISpElementKind_Movement:
- case kISpElementKind_DPad:
- dialogItemToNeedMapping[upDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[downDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[leftDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[rightDialogItem] = kUnsetIndex;
- break;
-
- case kISpElementKind_Delta:
- case kISpElementKind_Axis:
- if (itemIndex == upDialogItem || itemIndex == downDialogItem)
- {
- dialogItemToNeedMapping[upDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[downDialogItem] = kUnsetIndex;
- }
- else // (itemIndex == leftDialogItem || itemIndex == rightDialogItem)
- {
- dialogItemToNeedMapping[leftDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[rightDialogItem] = kUnsetIndex;
- }
- break;
- }
-
- // set new values
- if (newNeed == kUnsetIndex)
- {
- dialogItemToNeedMapping[itemIndex] = newNeed;
- }
- else switch (mNeeds[newNeed].theKind)
- {
- case kISpElementKind_Movement:
- case kISpElementKind_DPad:
- dialogItemToNeedMapping[upDialogItem] = newNeed;
- dialogItemToNeedMapping[downDialogItem] = newNeed;
- dialogItemToNeedMapping[leftDialogItem] = newNeed;
- dialogItemToNeedMapping[rightDialogItem] = newNeed;
- break;
-
- case kISpElementKind_Delta:
- case kISpElementKind_Axis:
- if (itemIndex == upDialogItem || itemIndex == downDialogItem)
- {
- dialogItemToNeedMapping[upDialogItem] = newNeed;
- dialogItemToNeedMapping[downDialogItem] = newNeed;
- }
- else // (itemIndex == leftDialogItem || itemIndex == rightDialogItem)
- {
- dialogItemToNeedMapping[leftDialogItem] = newNeed;
- dialogItemToNeedMapping[rightDialogItem] = newNeed;
- }
- break;
-
- case kISpElementKind_Button:
- dialogItemToNeedMapping[itemIndex] = newNeed;
- break;
-
- }
-
- mDirty = true;
- SetVirtualElements ();
-
- PlotPopupIcon(upDialogItem + mBaseDITLCount, ttNone);
- PlotPopupIcon(downDialogItem + mBaseDITLCount, ttNone);
- PlotPopupIcon(leftDialogItem + mBaseDITLCount, ttNone);
- PlotPopupIcon(rightDialogItem + mBaseDITLCount, ttNone);
- }
- }
-
-
- void ISpPlugInUI::HandleDeltaClick (
- Point where,
- short dialogItem,
- ISpElementLabel elementLabel,
- UInt32 minDeltaDialogItem,
- UInt32 maxDeltaDialogItem,
- UInt32 oldNeed,
- UInt32 &newNeed)
- {
- UInt32 * dialogItemToNeedMapping = GetDialogItemToNeedMapping();
-
- UInt32 itemIndex = dialogItem - mBaseDITLCount;
-
- if (CheckPopUpHit (where, dialogItem, kISpElementKind_Delta, elementLabel, validDeltaKinds, validDeltaKindsCount, oldNeed, newNeed) &&
- oldNeed != newNeed)
- {
- // clear old values (if necessary)
- if (oldNeed != kUnsetIndex) switch (mNeeds[oldNeed].theKind)
- {
- case kISpElementKind_Delta:
- case kISpElementKind_Axis:
- dialogItemToNeedMapping[minDeltaDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[maxDeltaDialogItem] = kUnsetIndex;
- break;
- }
-
- // set new values
- if (newNeed == kUnsetIndex)
- {
- dialogItemToNeedMapping[itemIndex] = newNeed;
- }
- else switch (mNeeds[newNeed].theKind)
- {
- case kISpElementKind_Delta:
- case kISpElementKind_Axis:
- dialogItemToNeedMapping[minDeltaDialogItem] = newNeed;
- dialogItemToNeedMapping[maxDeltaDialogItem] = newNeed;
- break;
-
- case kISpElementKind_Button:
- dialogItemToNeedMapping[itemIndex] = newNeed;
- break;
-
- }
-
- mDirty = true;
- SetVirtualElements ();
-
- PlotPopupIcon(minDeltaDialogItem + mBaseDITLCount, ttNone);
- PlotPopupIcon(maxDeltaDialogItem + mBaseDITLCount, ttNone);
- }
- }
-
-
- void ISpPlugInUI::HandleAxisClick (
- Point where,
- short itemNo,
- ISpElementLabel elementLabel,
- UInt32 minAxisDialogItem,
- UInt32 maxAxisDialogItem,
- UInt32 oldNeed,
- UInt32 &newNeed)
- {
- UInt32 * dialogItemToNeedMapping = GetDialogItemToNeedMapping();
-
- UInt32 itemIndex = itemNo - mBaseDITLCount;
-
- if (CheckPopUpHit (where, itemNo, kISpElementKind_Axis, elementLabel, validAxisKinds, validAxisKindsCount, oldNeed, newNeed) &&
- oldNeed != newNeed)
- {
- // clear old values (if necessary)
- if (oldNeed != kUnsetIndex) switch (mNeeds[oldNeed].theKind)
- {
- case kISpElementKind_Axis:
- dialogItemToNeedMapping[minAxisDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[maxAxisDialogItem] = kUnsetIndex;
- break;
- }
-
- // set new values
- if (newNeed == kUnsetIndex)
- {
- dialogItemToNeedMapping[itemIndex] = newNeed;
- }
- else switch (mNeeds[newNeed].theKind)
- {
- case kISpElementKind_Axis:
- dialogItemToNeedMapping[minAxisDialogItem] = newNeed;
- dialogItemToNeedMapping[maxAxisDialogItem] = newNeed;
- break;
-
- case kISpElementKind_Button:
- dialogItemToNeedMapping[itemIndex] = newNeed;
- break;
-
- }
-
- mDirty = true;
- SetVirtualElements ();
-
- PlotPopupIcon(minAxisDialogItem + mBaseDITLCount, ttNone);
- PlotPopupIcon(maxAxisDialogItem + mBaseDITLCount, ttNone);
- }
- }
-
- void ISpPlugInUI::HandlePedalAxisClick (
- Point where,
- short itemNo,
- ISpElementLabel elementLabel,
- UInt32 oldNeed,
- UInt32 &newNeed)
- {
- UInt32 * dialogItemToNeedMapping = GetDialogItemToNeedMapping();
-
- UInt32 itemIndex = itemNo - mBaseDITLCount;
-
- if (CheckPopUpHit (where, itemNo, kISpElementKind_Axis, elementLabel, validAxisKinds, validAxisKindsCount, oldNeed, newNeed) &&
- oldNeed != newNeed)
- {
- // set new value
- dialogItemToNeedMapping[itemIndex] = newNeed;
-
- mDirty = true;
- SetVirtualElements ();
-
- PlotPopupIcon(itemIndex + mBaseDITLCount, ttNone);
- }
- }
-
- void ISpPlugInUI::HandleButtonClick (
- Point where,
- short itemNo,
- ISpElementLabel elementLabel,
- UInt32 oldNeed,
- UInt32 &newNeed)
- {
- UInt32 * dialogItemToNeedMapping = GetDialogItemToNeedMapping();
-
- UInt32 itemIndex = itemNo - mBaseDITLCount;
-
- if (CheckPopUpHit (where, itemNo, kISpElementKind_Button, elementLabel, validButtonKinds, validButtonKindsCount, oldNeed, newNeed) &&
- oldNeed != newNeed)
- {
- // set new value
- dialogItemToNeedMapping[itemIndex] = newNeed;
-
- mDirty = true;
- SetVirtualElements ();
-
- PlotPopupIcon(itemIndex + mBaseDITLCount, ttNone);
- }
- }
-
- void ISpPlugInUI::HandleDPadClick (
- Point where,
- short itemNo,
- UInt32 upDialogItem,
- UInt32 downDialogItem,
- UInt32 leftDialogItem,
- UInt32 rightDialogItem,
- UInt32 oldNeed,
- UInt32 &newNeed)
- {
- UInt32 * dialogItemToNeedMapping = GetDialogItemToNeedMapping();
-
- UInt32 itemIndex = itemNo - mBaseDITLCount;
-
- // susbsitute this label for the element label for popup 'hinting' (IsAppropriateLabel)
- ISpElementLabel elementLabel;
-
- if (itemIndex == leftDialogItem || itemIndex == rightDialogItem)
- { elementLabel = kISpElementLabel_Axis_XAxis; }
- else
- { elementLabel = kISpElementLabel_Axis_YAxis; }
-
- if (CheckPopUpHit (where, itemNo, kISpElementKind_DPad, elementLabel, validPOVKinds, validPOVKindsCount, oldNeed, newNeed) &&
- oldNeed != newNeed)
- {
- // clear old values (if necessary)
- if (oldNeed != kUnsetIndex) switch (mNeeds[oldNeed].theKind)
- {
- case kISpElementKind_DPad:
- case kISpElementKind_Movement:
- dialogItemToNeedMapping[upDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[downDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[leftDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[rightDialogItem] = kUnsetIndex;
- break;
-
- case kISpElementKind_Axis:
- if (itemIndex == upDialogItem || itemIndex == downDialogItem)
- {
- dialogItemToNeedMapping[upDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[downDialogItem] = kUnsetIndex;
- }
- else // (itemIndex == leftDialogItem || itemIndex == rightDialogItem)
- {
- dialogItemToNeedMapping[leftDialogItem] = kUnsetIndex;
- dialogItemToNeedMapping[rightDialogItem] = kUnsetIndex;
- }
- break;
- }
-
- // set new values
- if (newNeed == kUnsetIndex)
- {
- dialogItemToNeedMapping[itemIndex] = newNeed;
- }
- else switch (mNeeds[newNeed].theKind)
- {
- case kISpElementKind_DPad:
- case kISpElementKind_Movement:
- dialogItemToNeedMapping[upDialogItem] = newNeed;
- dialogItemToNeedMapping[downDialogItem] = newNeed;
- dialogItemToNeedMapping[leftDialogItem] = newNeed;
- dialogItemToNeedMapping[rightDialogItem] = newNeed;
- break;
-
- case kISpElementKind_Axis:
- if (itemIndex == upDialogItem || itemIndex == downDialogItem)
- {
- dialogItemToNeedMapping[upDialogItem] = newNeed;
- dialogItemToNeedMapping[downDialogItem] = newNeed;
- }
- else // (itemIndex == leftDialogItem || itemIndex == rightDialogItem)
- {
- dialogItemToNeedMapping[leftDialogItem] = newNeed;
- dialogItemToNeedMapping[rightDialogItem] = newNeed;
- }
- break;
-
- case kISpElementKind_Button:
- dialogItemToNeedMapping[itemIndex] = newNeed;
- break;
-
- }
-
- mDirty = true;
- SetVirtualElements ();
-
- PlotPopupIcon(upDialogItem + mBaseDITLCount, ttNone);
- PlotPopupIcon(downDialogItem + mBaseDITLCount, ttNone);
- PlotPopupIcon(leftDialogItem + mBaseDITLCount, ttNone);
- PlotPopupIcon(rightDialogItem + mBaseDITLCount, ttNone);
- }
-
- }
-
- void MakeDialogItemInvisable (DialogRef theDialog, short itemNo)
- {
- WARNING(theDialog != nil, "MakeDialogItemInvisable dlog == nil");
- WARNING(CountDITL(theDialog) >= itemNo, "MakeDialogItemInvisable item >= CountDITL(dlog)");
- WARNING(itemNo > 0, "MakeDialogItemInvisable item <= 0");
-
- // Find the item's rectangle
- short itemType;
- Handle itemHandle;
- Rect itemBounds;
-
- GetDialogItem(theDialog, itemNo, &itemType, &itemHandle, &itemBounds);
-
- // make zero size rectangle
- itemBounds.bottom = itemBounds.top;
- itemBounds.right = itemBounds.left;
-
- SetDialogItem(theDialog, itemNo, itemType, itemHandle, &itemBounds);
-
- if (itemType & ctrlItem)
- HideControl((ControlHandle) itemHandle);
- }
-
- Boolean DialogItemIsInvisable (DialogRef theDialog, short itemNo)
- {
- WARNING(theDialog != nil, "DialogItemIsInvisable dlog == nil");
- WARNING(CountDITL(theDialog) >= itemNo, "DialogItemIsInvisable item >= CountDITL(dlog)");
- WARNING(itemNo > 0, "DialogItemIsInvisable item <= 0");
-
- Boolean isInvisable = false;
-
- // Find the item's rectangle
- short itemType;
- Handle itemHandle;
- Rect itemBounds;
-
- GetDialogItem(theDialog, itemNo, &itemType, &itemHandle, &itemBounds);
-
- if (itemBounds.bottom == itemBounds.top)
- isInvisable = true;
- else if (itemBounds.right == itemBounds.left)
- isInvisable = true;
-
- return isInvisable;
- }
-
- void SetDialogItemWidth (DialogRef theDialog, short itemNo, short width)
- {
- WARNING(theDialog != nil, "SetDialogItemWidth dlog == nil");
- WARNING(CountDITL(theDialog) >= itemNo, "SetDialogItemWidth item >= CountDITL(dlog)");
- WARNING(itemNo > 0, "SetDialogItemWidth item <= 0");
-
- // Find the item's rectangle
- short itemType;
- Handle itemHandle;
- Rect itemBounds;
-
- GetDialogItem(theDialog, itemNo, &itemType, &itemHandle, &itemBounds);
-
- // change the width
- itemBounds.right = itemBounds.left + width;
-
- SetDialogItem(theDialog, itemNo, itemType, itemHandle, &itemBounds);
- }
-
- OSStatus CreateDeviceFromResource( short resId,
- UInt32 refCon,
- ISpDeviceReference &device)
- {
- Handle h;
- OSStatus err;
- ISpDeviceDefinition def;
-
- // read the resource from the res file
- h = Get1Resource('isdv', resId);
- err = ResError();
-
- // debugging
- WARNING(h != nil, "CreateDeviceFromResource: Get1Resource failed (h == nil)");
- WARNING(err == noErr, "CreateDeviceFromResource: Get1Resource failed (err != noErr)");
- WARNING(GetHandleSize(h) == sizeof(def), "CreateDeviceFromResource: Get1Resource failed (bad handle size)");
-
- // error checking
- if (h == nil) { err = -1; }
- if (err) { return err; }
-
- // copy the handle to a structure and release the handle
- BlockMoveData(*h, &def, sizeof(def));
- ReleaseResource(h);
-
- // input sprocket call to create the device
- err = ISpDevice_New(&def, (ISpDriverFunctionPtr_MetaHandler) ISpPlugInUI::MetaHandler, refCon, &device);
-
- return err;
- }
-
- OSStatus CreateElementFromResource(short elementResId, short configResID, ISpDeviceReference device, ISpElementReference &element)
- {
- Handle h1; // handle to resource based element definition structure
- Handle h2; // handle to resource based element configuration info
- OSStatus err;
- ISpElementDefinitionStruct def; // actual element definition structure
-
- // read the element definition struct from a resource
- h1 = Get1Resource('isel', elementResId);
- err = ResError();
-
- // debugging
- WARNING(h1 != nil, "CreateElementFromResource: Get1Resource failed (h1 == nil)");
- WARNING(err == noErr, "CreateElementFromResource: Get1Resource failed (err != noErr)");
- WARNING(GetHandleSize(h1) == sizeof(def), "CreateElementFromResource: Get1Resource failed (bad handle size)");
-
- // error checking on element definition structure
- if (err) { return err; }
- if (h1 == nil) { return -1; }
-
- // read the configuration information from a resource
- h2 = Get1Resource('isei', configResID);
- err = ResError();
-
- // debugging
- WARNING(h2 != nil, "CreateElementFromResource: Get1Resource failed (h2 == nil)");
- WARNING(err == noErr, "CreateElementFromResource: Get1Resource failed (err != noErr)");
-
- // copy the element definition struct handle into the structure and fill in the config info
- BlockMoveData(*h1, &def, sizeof(def));
- if (h2)
- {
- HLock(h2);
- def.configInfo = *h2;
- def.configInfoLength = GetHandleSize(h2);
- }
-
- // set the device field
- def.device = device;
-
- // create the input sprocket device
- err = ISpElement_New(&def, &element);
-
- // release our handles
- HUnlock(h2);
- ReleaseResource(h1);
- ReleaseResource(h2);
-
- return err;
- }
-
- // ••• here and down are possible speed dependent functions
- #pragma mark ------ fast functions ------
- #if __MWERKS__
- #pragma optimize_for_size reset
- #endif
-
-
- void AxisToButtons(UInt32 axis, UInt32 buttons[2])
- {
- if (axis > 0xafffffff)
- { buttons[0] = kISpButtonUp; buttons[1] = kISpButtonDown; }
- else if (axis < 0x4fffffff)
- { buttons[0] = kISpButtonDown; buttons[1] = kISpButtonUp; }
- else
- { buttons[0] = kISpButtonUp; buttons[1] = kISpButtonUp; }
- }
-
- void PedalAxisToButton(UInt32 axis, UInt32 & button)
- {
- if (axis > 0x4fffffff)
- button = kISpButtonDown;
- else
- button = kISpButtonUp;
- }
-
- UInt32 AxisToDPad(UInt32 xAxis, UInt32 yAxis)
- {
- UInt32 hat;
-
- if (yAxis < 0x4fffffff)
- {
- if (xAxis < 0x4fffffff)
- { hat = kISpPadDownLeft; }
- else if (xAxis > 0xafffffff)
- { hat = kISpPadDownRight; }
- else
- { hat = kISpPadDown; }
- }
- else if (yAxis > 0xafffffff)
- {
- if (xAxis < 0x4fffffff)
- { hat = kISpPadUpLeft; }
- else if (xAxis > 0xafffffff)
- { hat = kISpPadUpRight; }
- else
- { hat = kISpPadUp; }
- }
- else
- {
- if (xAxis < 0x4fffffff)
- { hat = kISpPadLeft; }
- else if (xAxis > 0xafffffff)
- { hat = kISpPadRight; }
- else
- { hat = kISpPadIdle; }
- }
-
- return hat;
- }
-
- UInt32 BooleanDirectionsToDPad(UInt32 up, UInt32 left, UInt32 down, UInt32 right)
- {
- SInt8 x = 0;
- SInt8 y = 0;
-
- if (left) x--;
- if (right) x++;
-
- if (up) y++;
- if (down) y--;
-
- return DigitalAxisToDPad (x, y);
- }
-
- UInt32 DigitalAxisToDPad(SInt8 x, SInt8 y)
- {
- UInt32 result = kISpPadIdle;
-
- switch (x)
- {
- case -1:
- switch(y)
- {
- case 1: result = kISpPadUpLeft; break;
- case 0: result = kISpPadLeft; break;
- case -1: result = kISpPadDownLeft; break;
- }
- break;
- case 0:
- switch(y)
- {
- case 1: result = kISpPadUp; break;
- case 0: result = kISpPadIdle; break;
- case -1: result = kISpPadDown; break;
- }
- break;
- case 1:
- switch(y)
- {
- case 1: result = kISpPadUpRight; break;
- case 0: result = kISpPadRight; break;
- case -1: result = kISpPadDownRight; break;
- }
- break;
- }
-
- return result;
- }
-
- void DPadToButtonsAndAxis(UInt32 dpad, UInt32 buttons[4], UInt32 axis[2])
- {
- switch(dpad)
- {
- case kISpPadIdle:
- buttons[0] = kISpButtonUp;
- buttons[1] = kISpButtonUp;
- buttons[2] = kISpButtonUp;
- buttons[3] = kISpButtonUp;
-
- axis[0] = kISpAxisMiddle;
- axis[1] = kISpAxisMiddle;
- break;
-
- case kISpPadLeft:
- buttons[0] = kISpButtonUp;
- buttons[1] = kISpButtonDown;
- buttons[2] = kISpButtonUp;
- buttons[3] = kISpButtonUp;
-
- axis[0] = kISpAxisMinimum;
- axis[1] = kISpAxisMiddle;
- break;
-
- case kISpPadUpLeft:
- buttons[0] = kISpButtonDown;
- buttons[1] = kISpButtonDown;
- buttons[2] = kISpButtonUp;
- buttons[3] = kISpButtonUp;
-
- axis[0] = kISpAxisMinimum;
- axis[1] = kISpAxisMaximum;
- break;
-
- case kISpPadUp:
- buttons[0] = kISpButtonDown;
- buttons[1] = kISpButtonUp;
- buttons[2] = kISpButtonUp;
- buttons[3] = kISpButtonUp;
-
- axis[0] = kISpAxisMiddle;
- axis[1] = kISpAxisMaximum;
- break;
-
- case kISpPadUpRight:
- buttons[0] = kISpButtonDown;
- buttons[1] = kISpButtonUp;
- buttons[2] = kISpButtonUp;
- buttons[3] = kISpButtonDown;
-
- axis[0] = kISpAxisMaximum;
- axis[1] = kISpAxisMaximum;
- break;
-
- case kISpPadRight:
- buttons[0] = kISpButtonUp;
- buttons[1] = kISpButtonUp;
- buttons[2] = kISpButtonUp;
- buttons[3] = kISpButtonDown;
-
- axis[0] = kISpAxisMaximum;
- axis[1] = kISpAxisMiddle;
- break;
-
- case kISpPadDownRight:
- buttons[0] = kISpButtonUp;
- buttons[1] = kISpButtonUp;
- buttons[2] = kISpButtonDown;
- buttons[3] = kISpButtonDown;
-
- axis[0] = kISpAxisMaximum;
- axis[1] = kISpAxisMinimum;
- break;
-
- case kISpPadDown:
- buttons[0] = kISpButtonUp;
- buttons[1] = kISpButtonUp;
- buttons[2] = kISpButtonDown;
- buttons[3] = kISpButtonUp;
-
- axis[0] = kISpAxisMiddle;
- axis[1] = kISpAxisMinimum;
- break;
-
- case kISpPadDownLeft:
- buttons[0] = kISpButtonUp;
- buttons[1] = kISpButtonDown;
- buttons[2] = kISpButtonDown;
- buttons[3] = kISpButtonUp;
-
- axis[0] = kISpAxisMinimum;
- axis[1] = kISpAxisMinimum;
- break;
- }
- }
-
- UInt32 DPadReverseVertical(UInt32 dpad)
- {
- UInt32 result = 0;
-
- switch (dpad)
- {
- case kISpPadLeft:
- case kISpPadIdle:
- case kISpPadRight:
- result = dpad;
- break;
-
- case kISpPadUpLeft:
- result = kISpPadDownLeft;
- break;
-
- case kISpPadUp:
- result = kISpPadDown;
- break;
-
- case kISpPadUpRight:
- result = kISpPadDownRight;
- break;
-
- case kISpPadDownLeft:
- result = kISpPadUpLeft;
- break;
-
- case kISpPadDown:
- result = kISpPadUp;
- break;
-
- case kISpPadDownRight:
- result = kISpPadUpRight;
- break;
- }
-
- return result;
- }
-
-